﻿ ﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GarageGames.Torque.Core;
using GarageGames.Torque.Materials;
using GarageGames.Torque.SceneGraph;
using GarageGames.Torque.RenderManager;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace GarageGames.Torque.Materials
{
    public class DyeMaterial : SimpleMaterial
    {
        private const string STR_DyeColorR = "dyeColorR";
        private const string STR_DyeColorG = "dyeColorG";
        private const string STR_DyeColorB = "dyeColorB";
        private const string STR_DyeEffect = "DyeEffect";
        #region Constructors
        // Initializes a new instance of the SaturationMaterial class.
        public DyeMaterial()
        {
            EffectFilename = STR_DyeEffect;
        }
        #endregion

        //======================================================
        #region Public properties, operators, constants, and enums

        public Vector3 DyeColorR
        {
            get { return _dyeColorR; }
            set { _dyeColorR = value; }
        }

        public Vector3 DyeColorG
        {
            get { return _dyeColorG; }
            set { _dyeColorG = value; }
        }

        public Vector3 DyeColorB
        {
            get { return _dyeColorB; }
            set { _dyeColorB = value; }
        }

        #endregion

        //======================================================
        #region Private, protected, internal methods
        // Sets up this effect and selects a technique to render with.
        protected override string _SetupEffect(SceneRenderState srs, MaterialInstanceData materialData)
        {
            // For now, we'll accept whatever SimpleMaterial would use.
            return base._SetupEffect(srs, materialData);
        }

        // Performs per-object parameter setup.
        protected override void _SetupObjectParameters(RenderInstance renderInstance, SceneRenderState srs)
        {
            base._SetupObjectParameters(renderInstance, srs);

            EffectManager.SetParameter(_dyeColorRParameter, _dyeColorR);
            EffectManager.SetParameter(_dyeColorGParameter, _dyeColorG);
            EffectManager.SetParameter(_dyeColorBParameter, _dyeColorB);
        }

        // Loads the parameters from our effect into this material instance.
        protected override void _LoadParameters()
        {
            base._LoadParameters();

            _dyeColorRParameter = EffectManager.GetParameter(Effect, STR_DyeColorR);
            _dyeColorGParameter = EffectManager.GetParameter(Effect, STR_DyeColorG);
            _dyeColorBParameter = EffectManager.GetParameter(Effect, STR_DyeColorB);
        }

        // Clears references to parameters from this material.
        protected override void _ClearParameters()
        {
            _dyeColorRParameter = null;
            _dyeColorGParameter = null;
            _dyeColorBParameter = null;

            base._ClearParameters();
        }
        #endregion

        //======================================================
        #region Private, protected, internal fields
        // We'll add our parameters here shortly.

        private Vector3 _dyeColorR = new Vector3(1f, 1f, 1f);
        private Vector3 _dyeColorG = new Vector3(1f, 1f, 1f);
        private Vector3 _dyeColorB = new Vector3(1f, 1f, 1f);

        private EffectParameter _dyeColorRParameter;
        private EffectParameter _dyeColorGParameter;
        private EffectParameter _dyeColorBParameter;
        #endregion
    }
}
